﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Bank;
using Bank.Exceptions;


namespace BankUnitTest
{
    [TestClass]
    public class TestClient
    {
        [TestMethod]
        public void CreateEmptyAcccount()
        {
            Client client = new Client();         
            Assert.AreEqual("", client.FirstName);
            Assert.AreEqual("", client.LastName);
            Assert.AreEqual("", client.Pesel);
            Assert.AreEqual(false, client.Blocked);
        }

        [TestMethod]
        public void CreateFilledAcccount()
        {
            Client client = new Client("Jan" , "Kowalski" , "1");
            Assert.AreEqual("Jan", client.FirstName);
            Assert.AreEqual("Kowalski", client.LastName);
            Assert.AreEqual("1", client.Pesel);
        }

        [TestMethod]
        public void CreateCurrantAccount()
        {
            Client client = new Client("Jan", "Kowalski ", "1");
            // id is not valid, created for testing only
            IAccount newAccount = client.requestNewAccount(AccountType.CurrantAccount, 1, 0);
            if (newAccount == null)
            {
                throw new CreateAccountException("I can not create account with type: " + AccountType.CurrantAccount);
            }            
            Assert.AreEqual(AccountType.CurrantAccount, newAccount.GetType());           
        }

        [TestMethod]
        public void CreateCurrantAccount2()
        {
            Client client = new Client("Jan", "Kowalski ", "1");
            // id is not valid, created for testing only
            IAccount newAccount = client.requestNewAccount(AccountType.CurrantAccount, 1, new Money());
            if (newAccount == null)
            {
                throw new CreateAccountException("I can not create account with type: " + AccountType.CurrantAccount);
            }
            Assert.AreEqual(AccountType.CurrantAccount, newAccount.GetType());
        }

        [TestMethod]
        public void CreateDepositAccount()
        {
            Client client = new Client("Jan", "Kowalski ", "1");
            // id is not valid, created for testing only
            IAccount newAccount = client.requestNewAccount(AccountType.DepositAccount, 1, 0);
            if (newAccount == null)
            {
                throw new CreateAccountException("I can not create account with type: " + AccountType.DepositAccount);
            }
            Assert.AreEqual(AccountType.DepositAccount, newAccount.GetType());
        }

        [TestMethod]
        public void CreateDepositAccount2()
        {
            Client client = new Client("Jan", "Kowalski ", "1");
            // id is not valid, created for testing only
            IAccount newAccount = client.requestNewAccount(AccountType.DepositAccount, 1, new Money());
            if (newAccount == null)
            {
                throw new CreateAccountException("I can not create account with type: " + AccountType.DepositAccount);
            }
            Assert.AreEqual(AccountType.DepositAccount, newAccount.GetType());
        }


        [TestMethod]
        public void ChangeInterestCalculator()
        {

            Banker banker = new Banker("Jan", "Kowalski");
            banker.addClient("Tomek", "Nowak", "1");


            Client client = banker.getClient("1");

            IAccount firstAccount = client.requestNewAccount(AccountType.CurrantAccount, client.ClientID, 0);
            IAccount secondAccount = client.requestNewAccount(AccountType.CurrantAccount, client.ClientID, 0);

            client.makePayment(1000, firstAccount.Number);
            client.makePayment(1000, firstAccount.Number);
            client.makePayment(1000, firstAccount.Number);

            client.makePayment(1000, secondAccount.Number);
            client.makePayment(1000, secondAccount.Number);
            client.makePayment(1000, secondAccount.Number);

            Console.WriteLine("First Account Balance = " + firstAccount.Ballance);
            Console.WriteLine("Second Account Balance = " + secondAccount.Ballance);

            client.changeInterestCalculator(InterestCalculatorType.SimpleInterestCalculator, secondAccount.Number );

            banker.calculateInterests(client.ClientID, firstAccount.Number);
            banker.calculateInterests(client.ClientID, secondAccount.Number);

            Console.WriteLine("First Account Balance = " + firstAccount.Ballance);


        }
    }
}
